var mongoose = require("../common/db")

var user = new mongoose.Schema({
	username: String,
	password: String,
	userMail: String,
	userPhone: String,
	userAdmin: Boolean, // 是否管理员
	userPower: Number, // 启用状态
	userStop: Boolean, // 封停状态
})

// 用户查找方法
user.statics.findAll = function (callBack) {
	this.find({}, callBack)
}

// 使用用户名查找
user.statics.findByUsername = function (name, callBack) {
	this.findOne({ username: name }, callBack)
}

// 使用id查找用户信息
user.statics.findById = function (id, callBack) {
	this.findOne({ _id: id }, callBack)
}

// 登录匹配是不是拥有相同的用户名和密码并且没有处于封停状态
user.statics.findUserLogin = function (name, password, callBack) {
	this.findOne({ username: name, password: password, userStop: false }, callBack)
}

// 根据邮箱、电话、用户名找到用户
user.statics.findUserPassword = function (name, mail, phone, callBack) {
	this.findOne({ username: name, userMail: mail, userPhone: phone }, callBack)
}

var userModel = mongoose.model("User", user)

module.exports = userModel
